package com.example.wyz.classplus.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.wyz.classplus.R;
import com.example.wyz.classplus.base.BaseFragment;
import com.example.wyz.classplus.contract.fgm.MainMessageContract;
import com.example.wyz.classplus.presenter.MainMessagePresenter;
import com.example.wyz.classplus.ui.activity.CampusNoticeMsgActivity;
import com.example.wyz.classplus.ui.activity.NoticeMsgActivity;
import com.example.wyz.classplus.ui.activity.SubscribeMsgActivity;
import com.example.wyz.classplus.ui.adapter.ClassMessageAdapter;
import com.example.wyz.classplus.ui.custom.ExpandedLinerLayoutManager;

import butterknife.BindView;

/**
 * Created by 10153 on 2017/5/26.
 */

public class MainMessageFragment extends BaseFragment<MainMessageContract.Presenter>
        implements MainMessageContract.View, View.OnClickListener{

    @BindView(R.id.rec_message_class) RecyclerView mClassMessage;
    @BindView(R.id.layout_main_msg_subscribe) LinearLayout mSubscribeMsgLayout;
    @BindView(R.id.layout_main_msg_notice) LinearLayout mNoticeLayout;
    @BindView(R.id.layout_main_msg_campus_atvs) LinearLayout mCampusAtvsLayout;
    @BindView(R.id.layout_main_msg_campus_notice) LinearLayout mCampusNoticeLayout;
    @BindView(R.id.tv_main_msg_subscribe) TextView mSubscribeMsgTV;
    @BindView(R.id.tv_main_msg_notice) TextView mNoticeTV;
    @BindView(R.id.tv_main_msg_campus_atvs) TextView mCampusAtvsTV;
    @BindView(R.id.tv_main_msg_campus_notice) TextView mCampusNoticeTV;

    //BaseFragment方法重写&接口实现

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        initRecyclerView();
        initOnClickListener();
        return view;
    }

    @Override
    protected void initPresenter() {
        mPresenter = new MainMessagePresenter(this.mContext, this);
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_main_message;
    }

    //listener接口实现

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.layout_main_msg_subscribe:
                mPresenter.startActivity(SubscribeMsgActivity.class);
                break;
            case R.id.layout_main_msg_notice:
                mPresenter.startActivity(NoticeMsgActivity.class);
                break;
            case R.id.layout_main_msg_campus_atvs:
                //mPresenter.startActivity();
                break;
            case R.id.layout_main_msg_campus_notice:
                mPresenter.startActivity(CampusNoticeMsgActivity.class);
                break;
            default:
                break;
        }
    }

    //contract.view 接口实现


    //私有方法
    private void initRecyclerView(){
        ExpandedLinerLayoutManager manager = new ExpandedLinerLayoutManager(this.mContext, LinearLayoutManager.VERTICAL, true);
        ClassMessageAdapter adapter = new ClassMessageAdapter(this.mContext);
        mClassMessage.setLayoutManager(manager);
        mClassMessage.setAdapter(adapter);
        mClassMessage.setNestedScrollingEnabled(false);
    }

    private void initOnClickListener(){
        mSubscribeMsgLayout.setOnClickListener(this);
        mNoticeLayout.setOnClickListener(this);
        mCampusAtvsLayout.setOnClickListener(this);
        mCampusNoticeLayout.setOnClickListener(this);
    }
}
